home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / VSPRINTF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.7 KB  |  43 lines

  1. /* vsprintf.c --- p 483 */
  2. #include <stdio.h>
  3. #include <stdarg.h>                     /* ANSI C compatible  */
  4. #include <conio.h>
  5. void error_handler(char *,...);
  6. char filename[80] = "COMMAND.COM";
  7. main()
  8. {
  9.     int offset = 0x232A;
  10.                 /* Assume we are already in text mode     */
  11.     clrscr();                                  /* Clear  screen */
  12.     window (10, 10, 70, 15);             /* Define text window*/
  13.     textattr (YELLOW+(RED <<4));         /* Set background to red */
  14.     clrscr();                             /* clear out text window */
  15.         /* Once a text window is defined all text positions are
  16.          * relative to upper left corner of the window. Notice
  17.          * that this can be used for pop_up menus. */
  18.     gotoxy(1,1);                         /* Set text position   */
  19.         /* Call the error handler to print an error message.
  20.          * First just a single line. Then a more detailed
  21.          * message with more arguments. */
  22.     error_handler("System error\n");
  23.     error_handler("File %s at offset %x\n", filename, offset);
  24. }
  25.                     /*----------------------------*/
  26.         /* error_handler: accepts variable number of arguments
  27.         * and prints messages */
  28. void error_handler(char *my_format,...)
  29. {
  30.     va_list arg_pointer;
  31.     char buffer[80];               /* Buffer for text string */
  32.             /* Use va_start macro to get to the start of the
  33.              * variable number of arguments. This will alter the
  34.              * pointer arg_pointer to point to the list of
  35.              * variables to be printed. */
  36.     va_start(arg_pointer, my_format);
  37.     vsprintf(buffer, my_format, arg_pointer);
  38.             /* Now display the message by calling cputs */
  39.     cputs (buffer);
  40.     cputsJ("\r");
  41.             /* Use the va_end macro to reset the arg_pointer */
  42.     va_end(arg_pointer);
  43. }